package com.oracle.rentcar.test;

import com.oracle.rentcar.RentcarApplication;
import com.oracle.rentcar.mapper.EmpMapper;
import com.oracle.rentcar.pojo.Customer;
import com.oracle.rentcar.pojo.Emp;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {RentcarApplication.class})
public class EmpTest1 {

    @Autowired
    private EmpMapper empMapper;

    @Test
    public void testCountEmp() {
        Long count = empMapper.getEmpRowCount();
        System.out.println("总计" + count + "个员工");
    }

    @Test
    public void testSelectEmp() {
        List<Map<String, Object>> maps = empMapper.selectEmp();

        for (Map<String, Object> map : maps) {
            System.out.println(map);
        }
    }

    @Test
    public void testSelectEmpById() {
        Emp emp = empMapper.selectEmpById(2);
        System.out.println(emp);
    }

    @Test
    public void testInsertEmp() {
        Emp emp = new Emp();

        emp.setEmpId("jiangbo234");
        emp.setEmpName("黑小绿234");
        emp.setPassword("123456");
        emp.setRoleId(1);
        emp.setStoreId(2);

        int n = empMapper.insertEmp(emp);
        System.out.println("n:"+n);
        System.out.println(emp.getId());
    }

    @Test
    public void testDeleteEmpById() {
        int n = empMapper.deleteEmpById(345);
        System.out.println(n);
    }

    @Test
    public void testBatchDeleteEmp() {
        List<Integer> list = new ArrayList<Integer>();
        list.add(345);
        list.add(346);
        list.add(348);

        int n = empMapper.batchDeleteEmp(list);
        System.out.println(n);
    }

    @Test
    public void testUpdateEmpById() {
        Emp emp = new Emp();
        emp.setId(347);
        emp.setPassword("123");

        int n = empMapper.updateEmpById(emp);
        System.out.println(n);
    }

    @Test
    public void testEmpLogin() {
        Emp emp = new Emp();
        emp.setEmpId("你好");
        emp.setPassword("123");

        Map<String, Object> map = empMapper.empLogin(emp);

        if (map == null) {
            System.out.println("用户名或者密码错误");
        } else {
            System.out.println("登录成功！");
            Set<String> set = map.keySet();
            for (String s : map.keySet()) {
                System.out.println(s + ": " + map.get(s));
            }
        }
    }

    @Test
    public void testSelectEmpByParams(){
        List<Map<String, Object>> maps = empMapper.selectEmpByParams("小", "", 3);
        for (Map<String, Object> map : maps) {
            System.out.println(map);
        }
    }

    /*@Test
    public void testSelectEmpByParam(){
        List<Map<String, Object>> maps = empMapper.selectEmpByParam(1);
        for (Map<String, Object> map : maps) {
            System.out.println(map);
        }
    }*/

}
